package com.example.wc.logindemo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by hui on 2017/4/6.
 */

public class DateByDate {

    public static long TimeByDate(Date date){
        long time=date.getTime();
        return time;
    }

    //获得date当天00:00点的date
    public static long DayByDate(Date date) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E, MMMM dd, yyyy");
        String dateString = simpleDateFormat.format(date);
        Date day = simpleDateFormat.parse(dateString);
        return day.getTime();

    }

    //获得date当天整点时间,最后改成获得date当天所在一个小时的起始整点时间，此方法可删除
    public static long BeginOverByDate(Date date, int i) throws ParseException{
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("E, MMMM dd, yyyy");
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("E, MMMM dd, yyyy, kk:mm");
        String dateString = simpleDateFormat1.format(date);
        String dateStringBeginOver = dateString+", "+IntToStr(i)+":00";
        Date day = simpleDateFormat2.parse(dateStringBeginOver);
        return day.getTime();
    }

    //获得date当天所在一个小时的起始整点时间
    public static long BeginByDate(Date date) throws ParseException{
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("E, MMMM dd, yyyy, kk");
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("E, MMMM dd, yyyy, kk:mm");
        String dateString = simpleDateFormat1.format(date);
        String dateStringBeginOver = dateString+":00";
        Date day = simpleDateFormat2.parse(dateStringBeginOver);
        return day.getTime();
    }

    //01 02 03……
    public static String IntToStr(int i){
        String j="";
        if(i<=9)
            j="0"+i;
        else
            j=String.valueOf(i);
        return j;
    }
}
